<?php

namespace app\common\MyLibrary;

use DateTime;
use InvalidArgumentException;
use think\Log;

class Utils
{
  /**
   * Nursecount模型对象
   * @var \app\admin\model\fssy\Nursecount
   */
  protected $model = null;

  /**
   * 计算年龄
   *
   * @param [type] $birthDate = 1980-11-30
   * @return int 年龄 = 44
   */
  public static function calculateAge($birthDate)
  {
    // 确保日期格式正确
    $birthDate = new DateTime($birthDate);
    $currentDate = new DateTime();

    // 手动计算年龄
    $age = $currentDate->format('Y') - $birthDate->format('Y');
    if ($currentDate->format('md') < $birthDate->format('md')) {
      $age--;
    }

    return $age;
  }

  /**
   * 计算工作年限
   *
   * @param [type] $hireDate = 2012-01-01
   * @return string 工作年限 = 12年11月
   */
  public static function calculateYearsMonths($hireDate)
  {
    // 确保日期格式正确
    $hireDate = new DateTime($hireDate);
    $currentDate = new DateTime();

    // 计算工作年限
    $interval = $currentDate->diff($hireDate);
    $years = $interval->y;
    $months = $interval->m;

    // 返回格式化的工作年限
    return $years . '年' . $months . '月';
  }

  /**
   * 生成指定年份的季度信息
   *Str
   * @param [Str] $min_year   "2022"
   * @param [Str] $min_month  "01"
   * @param [Str] $max_year   "2024"
   * @param [Str] $max_month  "12"
   * @return  // 
   * 0:  "2022-01-01 ~ 2022-03-31 一季度"
   * 1:  "2022-04-01 ~ 2022-06-30 二季度"
   * 2:  "2022-07-01 ~ 2022-09-30 三季度"
   * 3:  "2022-10-01 ~ 2022-12-31 四季度"
   * 4:  "2023-01-01 ~ 2023-03-31 一季度"
   * 5:  "2023-04-01 ~ 2023-06-30 二季度"
   * 6:  "2023-07-01 ~ 2023-09-30 三季度"
   * 7:  "2023-10-01 ~ 2023-12-31 四季度"
   * 8:  "2024-01-01 ~ 2024-03-31 一季度"
   * 9:  "2024-04-01 ~ 2024-06-30 二季度"
   * 10  :"2024-07-01 ~ 2024-09-30 三季度"
   * 11  :"2024-10-01 ~ 2024-12-31 四季度"
   */
  public static function generateQuarterDates($min_year, $min_month, $max_year, $max_month)
  {
    // 中文季度映射
    $quarter_names = ["一季度", "二季度", "三季度", "四季度"];
    $quarters = [];

    // 定义固定的季度区间
    $quarter_dates = [
      "01-01 ~ 03-31", // 一季度
      "04-01 ~ 06-30", // 二季度
      "07-01 ~ 09-30", // 三季度
      "10-01 ~ 12-31"  // 四季度
    ];

    // 计算从哪个季度开始
    $start_quarter = ceil((int)$min_month / 3);  // 计算从哪个季度开始
    // 计算到哪个季度结束
    $end_quarter = ceil((int)$max_month / 3);  // 计算到哪个季度结束

    // 遍历从最小年份到最大年份的每个年份
    for ($year = $min_year; $year <= $max_year; $year++) {
      // 如果是最小年份，开始季度需要从 $start_quarter 开始
      if ($year == $min_year) {
        $start = $start_quarter - 1;  // 起始季度的索引
      } else {
        $start = 0;  // 其他年份从一季度开始
      }

      // 如果是最大年份，结束季度需要到 $end_quarter 结束
      if ($year == $max_year) {
        $end = $end_quarter - 1;  // 结束季度的索引
      } else {
        $end = 3;  // 其他年份直到四季度
      }

      // 遍历每个季度
      for ($quarter = $start; $quarter <= $end; $quarter++) {
        // 获取季度名称
        $quarter_name = $quarter_names[$quarter];

        // 计算季度的开始日期和结束日期
        $start_date = "$year-" . substr($quarter_dates[$quarter], 0, 5); // 获取开始日期
        $end_date = "$year-" . substr($quarter_dates[$quarter], strpos($quarter_dates[$quarter], '~') + 1); // 获取结束日期
        $end_date = str_replace(" ", "", $end_date);
        // 将季度信息添加到数组中
        $quarters[] = "$start_date ~ $end_date $quarter_name";
      }
    }

    return $quarters;
  }

  /**
   * 将中文季度映射为日期时间
   *
   * @param [Arr] generateQuarterDates 返回值  "2022-01-01 ~ 2022-03-31 一季度"
   * @return 
   *  *  [
   *   "2022-04-01 00:00:00~2022-06-30 23:59:59",
   *   "2022-07-01 00:00:00~2022-09-30 23:59:59",
   *   "2022-10-01 00:00:00~2022-12-31 23:59:59",
   *   "2024-01-01 00:00:00~2023-03-31 23:59:59",
   *   "2024-04-01 00:00:00~2023-06-30 23:59:59",
   *   "2024-07-01 00:00:00~2023-09-30 23:59:59",
   *   "2024-10-01 00:00:00~2023-12-31 23:59:59",
   *   "2024-01-01 00:00:00~2024-03-31 23:59:59",
   *   "2024-04-01 00:00:00~2024-06-30 23:59:59",
   *   "2024-07-01 00:00:00~2024-09-30 23:59:59",
   *   "2024-10-01 00:00:00~2024-12-31 23:59:59"
   *  ]
   */
  public static function convertQuarterDates($inputDates)
  {
    $outputDates = [];

    foreach ($inputDates as $dateString) {
      // 使用 " ~ " 分割日期字符串
      list($startDate, $endDateWithQuarter) = explode(' ~ ', $dateString);

      // 分离结束日期和季度信息
      list($endDate, $quarter) = explode(' ', $endDateWithQuarter);

      // 添加时间部分
      $startDateWithTime = $startDate . ' 00:00:00';
      $endDateWithTime = $endDate . ' 23:59:59';

      // 重新组合日期字符串
      $outputDates[] = $startDateWithTime . '~' . $endDateWithTime;
    }

    return $outputDates;
  }

  /**
   * 将日期时间数组转换为时间戳数组
   *
   * @param [Arr] convertQuarterDates 返回值 "2022-04-01 00:00:00~2022-06-30 23:59:59",
   * @return 
   *[
   *      { "start": 1704038400, "end": 1711900799 },
   *      { "start": 1711900800, "end": 1719763199 },
   *      { "start": 1719763200, "end": 1727711999 },
   *      { "start": 1727712000, "end": 1735660799 }
   * ]
   */
  public static function dateTimeArrToTimestamps($dateTimeArr)
  {
    // 设置默认时区为“PRC”
    date_default_timezone_set("PRC");

    $timestampArr = [];

    foreach ($dateTimeArr as $dateTimeRange) {
      // 使用 "~" 分割开始时间和结束时间
      list($startDateTime, $endDateTime) = explode('~', $dateTimeRange);

      // 将开始时间和结束时间转换为时间戳
      $startTimestamp = strtotime($startDateTime);
      $endTimestamp = strtotime($endDateTime);

      // 将时间戳添加到结果数组中
      $timestampArr[] = [
        'start' => $startTimestamp,
        'end' => $endTimestamp
      ];
    }

    return $timestampArr;
  }

  /***
   * 将数组中不存在的键值对添加到数组中，并将值设置为0
   */
  public static function arrSetZero($Arr, $field)
  {
    $counts = [];
    foreach ($Arr as $item) {
      // 检查是否已经存在对应的键，避免重复添加
      if (!array_key_exists($item[$field], $counts)) {
        $counts[$item[$field]] = 0;
      }
    }
    return $counts;
    // $counts = [];
    // foreach ($Arr as $item) {
    //   // 检查是否存在键值并避免访问错误
    //   if (isset($item[$field])) {
    //     if (!array_key_exists($item[$field], $counts)) {
    //       $counts[$item[$field]] = 0;
    //     }
    //   }
    // }
    // return $counts;
  }

  /**
   * 返回年资范围
   *
   * @param [type] $input = 12年11月
   * @return "10≥y<20年资人数"
   */
  public static function calcYearsStep($input)
  {
    // 正则表达式匹配输入的年份和月份
    if (preg_match('/(\d{1,2})年(\d{1,2})月/', $input, $matches)) {
      // 提取年份和月份
      $years = (int) $matches[1];
      $months = (int) $matches[2];
      // 判断年资的范围
      if ($years < 1 || ($years == 1 && $months == 0)) {
        return "<1年资人数";
      } elseif ($years >= 1 && $years < 2) {
        return "1≤y<2年资人数";
      } elseif ($years >= 2 && $years < 5) {
        return "2≤y<5年资人数";
      } elseif ($years >= 5 && $years < 10) {
        return "5≤y<10年资人数";
      } elseif ($years >= 10 && $years < 20) {
        return "10≥y<20年资人数";
      } elseif ($years >= 20) {
        return "≥20年资人数";
      }
    }
    return "输入无效";
  }

  /**
   * 插入数据库 nurse6** 季报-职称人数、学历人数、年资人数数据
   *
   * @param [type] $quarterArr    "2024-01-01 ~ 2024-03-31 一季度"
   * @param [type] $itemArr       ( [护士] => 0[护师] => 1, [主管护师] => 0, [副主任护师] => 0, [主任护师] => 0 )
   * @param [type] $index         数组索引
   * @param [type] $type          'jobTitle'
   * @return void
   */
  public static function insertNurse6DB($quarterArr, $itemArr, $index, $type)
  {
    // 根据类型构造数据数组
    if ($type === 'jobTitle') {
      $data = [
        'time_querter' => $quarterArr[$index],
        'zc01rs' => $itemArr['护士'] ?? 0,
        'zc02rs' => $itemArr['护师'] ?? 0,
        'zc03rs' => $itemArr['主管护师'] ?? 0,
        'zc04rs' => $itemArr['副主任护师'] ?? 0,
        'zc05rs' => $itemArr['主任护师'] ?? 0,
        'createtime' => time(),
        'updatetime' => time()
      ];
      $model = new \app\admin\model\fssy\Nsqtrt6jt();
    } elseif ($type === 'education') {
      $data = [
        'time_querter' => $quarterArr[$index],
        'xl01rs' => $itemArr['中专'] ?? 0,
        'xl02rs' => $itemArr['大专'] ?? 0,
        'xl03rs' => $itemArr['本科'] ?? 0,
        'xl04rs' => $itemArr['硕士'] ?? 0,
        'xl05rs' => $itemArr['博士'] ?? 0,
        'createtime' => time(),
        'updatetime' => time()
      ];
      $model = new \app\admin\model\fssy\Nsqtrt6eb();
    } elseif ($type === 'yearPay') {
      $data = [
        'time_querter' => $quarterArr[$index],
        'nz01rs' => $itemArr['<1年资人数'] ?? 0,
        'nz02rs' => $itemArr['1≤y<2年资人数'] ?? 0,
        'nz03rs' => $itemArr['2≤y<5年资人数'] ?? 0,
        'nz04rs' => $itemArr['5≤y<10年资人数'] ?? 0,
        'nz05rs' => $itemArr['10≥y<20年资人数'] ?? 0,
        'nz06rs' => $itemArr['≥20年资人数'] ?? 0,
        'createtime' => time(),
        'updatetime' => time()
      ];
      $model = new \app\admin\model\fssy\Nsqtrt6nz();
    } else {
      throw new \Exception("Invalid type specified.");
    }

    try {
      $result = $model->insert($data);
    } catch (\Exception $e) {
      // 处理异常，例如记录日志或返回错误信息
      error_log("Error inserting data: " . $e->getMessage());
      throw $e;
    }
  }

  /**
   * 根据日期时间字符串返回对应的季度信息
   *
   * @param string $dateTimeStr 日期时间字符串，格式如 "2023-01-01 11:00:00"
   * @return string 季度信息，格式如 "2023年 一季度"
   */
  public static function getQuarterInfo($dateTimeStr)
  {
    // 创建 DateTime 对象
    $dateTime = new DateTime($dateTimeStr);

    // 获取年份
    $year = $dateTime->format('Y');

    // 获取月份
    $month = (int)$dateTime->format('m');

    // 根据月份确定季度
    if ($month >= 1 && $month <= 3) {
      $quarter = '一季度';
    } elseif ($month >= 4 && $month <= 6) {
      $quarter = '二季度';
    } elseif ($month >= 7 && $month <= 9) {
      $quarter = '三季度';
    } else {
      $quarter = '四季度';
    }

    // 返回结果
    return $year . '年 ' . $quarter;
  }

  /**
   * 根据两个季度信息字符串返回这两个季度之间的所有季度信息数组
   *
   * @param string $startQuarter 开始季度信息，格式如 "2023年 一季度"
   * @param string $endQuarter 结束季度信息，格式如 "2024年 四季度"
   * @return array 季度信息数组，格式如 ["2023年 一季度", "2023年 二季度", ..., "2024年 四季度"]
   */
  public static function getQuartersBetween($startQuarter, $endQuarter)
  {
    // 定义季度名称数组
    $quarters = ["一季度", "二季度", "三季度", "四季度"];

    // 解析开始和结束季度的年份和季度
    preg_match('/(\d{4})年 (\S+)/', $startQuarter, $startMatches);
    preg_match('/(\d{4})年 (\S+)/', $endQuarter, $endMatches);

    // 获取开始和结束的年份和季度
    $startYear = $startMatches[1];
    $startQuarterIndex = array_search($startMatches[2], $quarters) + 1; // 获取开始季度的索引

    $endYear = $endMatches[1];
    $endQuarterIndex = array_search($endMatches[2], $quarters) + 1; // 获取结束季度的索引

    // 存放所有季度的结果
    $result = [];

    // 生成季度信息
    while ($startYear < $endYear || ($startYear == $endYear && $startQuarterIndex <= $endQuarterIndex)) {
      // 将季度封装为包含 `quarter` 键的数组
      $result[] = ['quarter' => $startYear . '年 ' . $quarters[$startQuarterIndex - 1]];

      // 移动到下一个季度
      $startQuarterIndex++;
      if ($startQuarterIndex > 4) {
        $startQuarterIndex = 1;
        $startYear++;
      }
    }

    return $result;
  }

  /***
   * 根据季度信息字符串返回季度的开始和结束日期
   * @param string $quarterString 季度信息字符串，格式如 "2023年 一季度"
   * @return array 包含 `start_time` 和 `end_time` 键的数组，格式如 ["start_time" => "2023-01-01", "end_time" => "2023-03-31"]
   */
  public static function getQuarterDateRange($quarterString)
  {
    // 提取年份和季度
    preg_match('/(\d{4})年\s*(一|二|三|四)季度/', $quarterString, $matches);

    if (count($matches) != 3) {
      return null; // 如果匹配失败，返回null
    }

    $year = $matches[1];
    $quarter = $matches[2];

    // 设置季度的开始和结束日期
    switch ($quarter) {
      case '一':
        $start_date = "$year-01-01";
        $end_date = "$year-03-31";
        break;
      case '二':
        $start_date = "$year-04-01";
        $end_date = "$year-06-30";
        break;
      case '三':
        $start_date = "$year-07-01";
        $end_date = "$year-09-30";
        break;
      case '四':
        $start_date = "$year-10-01";
        $end_date = "$year-12-31";
        break;
      default:
        return null; // 如果没有匹配到正确的季度，返回null
    }

    return [
      'start_time' => $start_date,
      'end_time' => $end_date
    ];
  }
  /**
   * 根据季度信息字符串返回上一个季度信息字符串
   * 
   * @param string $quarterString 季度信息字符串，格式如 "2023年 一季度"
   * @return string 上一个季度信息字符串，格式如 "2022年 四季度"
   */
  public static function getPreviousQuarter($quarterString)
  {
    // 提取年份和季度
    preg_match('/(\d{4})年\s*(一|二|三|四)季度/', $quarterString, $matches);

    if (count($matches) != 3) {
      return null; // 如果匹配失败，返回null
    }

    $year = $matches[1];
    $quarter = $matches[2];

    // 根据季度计算上一个季度
    switch ($quarter) {
      case '一':
        $previous_quarter = '四';
        $previous_year = $year - 1;
        break;
      case '二':
        $previous_quarter = '一';
        $previous_year = $year;
        break;
      case '三':
        $previous_quarter = '二';
        $previous_year = $year;
        break;
      case '四':
        $previous_quarter = '三';
        $previous_year = $year;
        break;
      default:
        return null; // 如果没有匹配到正确的季度，返回null
    }

    return $previous_year . "年 " . $previous_quarter . "季度";
  }

  /**
   * 生成从开始日期到结束日期的每个月的数组
   *
   * @param string $startDate 开始日期，格式为 "Y-m" (例如 "2024-10")
   * @param string $endDate 结束日期，格式为 "Y-m"  (例如 "2024-12")
   * @return array 月份数组，格式为 ["Y-m", ...] (例如 ["2024-10", "2024-11", "2024-12"])
   */
  public static function generateMonthlyRange($startDate, $endDate)
  {
    // 格式化输入日期字符串为 DateTime 对象
    $start = DateTime::createFromFormat('Y-m', $startDate);
    $end = DateTime::createFromFormat('Y-m', $endDate);

    // 如果输入的日期格式不正确，抛出异常
    if (!$start || !$end) {
      throw new InvalidArgumentException('Invalid date format. Expected format: Y-m');
    }

    // 初始化月份数组
    $months = [];

    // 遍历从开始日期到结束日期的每个月
    while ($start <= $end) {
      // 将当前月份添加到数组中
      $months[] = ["month" => $start->format('Y-m')];

      // 增加一个月
      $start->modify('+1 month');
    }

    return $months;
  }

  /**
   * 根据日期字符串获取月份的开始和结束日期
   *
   * @param [type] $dateString 日期字符串，格式如 "2023-01"
   * @return 
   * array 包含 `start_time` 和 `end_time`, start_timestamp, end_timestamp 键的数组，
   * 格式如 ["start_time" => "2023-01-01 00:00:00", "start_timestamp" => 1609459200, "end_time" => "2023-01-31 23:59:59", "end_timestamp" => 1611137599]
   */
  public static function getMonthStartAndEnd($dateString)
  {
    date_default_timezone_set('Asia/Shanghai');
    // 确保月份是两位数
    $normalizedDate = preg_replace('/^(\d{4})-(\d)$/', '$1-0$2', $dateString);

    // 解析输入的日期字符串
    $date = DateTime::createFromFormat('Y-m', $normalizedDate);
    if (!$date || $date->format('Y-m') !== $normalizedDate) {
      throw new \Exception("Invalid date format. Expected format: Y-m");
    }

    // 获取年份和月份
    $year = (int)$date->format('Y');
    $month = (int)$date->format('m');

    // 计算当月的第一天
    $start_time = $date->setDate($year, $month, 1)->setTime(0, 0, 0)->format('Y-m-d H:i:s');

    // 克隆一个对象用于计算月末，避免影响原对象
    $end_date = clone $date;
    $end_date->modify('last day of this month')->setTime(23, 59, 59);

    // 将日期转换为时间戳
    $start_timestamp = strtotime($start_time);
    $end_timestamp = strtotime($end_date->format('Y-m-d H:i:s'));

    return [
      'start_time' => $start_time,
      'start_timestamp' => $start_timestamp,
      'end_time' => $end_date->format('Y-m-d H:i:s'),
      'end_timestamp' => $end_timestamp
    ];
  }

  // 查询nuserinfo表，季报 职称人数、学历人数、年资人数数据
  /**
   * 根据科室名称或全部科室 查询 科室id、职称、学历、年资人数
   *
   *
   * @param [type] $department
   * @param [type] $start_date
   * @param [type] $end_date
   * @return void 返回数组
   */
  public static function getNurseQuarterCountData($department, $start_date, $end_date)
  {
    // 根据科室名称或全部科室 查询 科室id
    if ($department == '全部科室') {
      $departmentID = "all";  // 全部科室
    } else {
      // 查询数据库, 获取科室id
      $departmentModel = new \app\admin\model\dicts\Department;
      $departmentInfo = $departmentModel->where('department', $department)->find();
      $departmentID = $departmentInfo['id'];  // 科室id
    }

    $min_updatetime = $start_date;  // 2023-01-01
    $max_updatetime = $end_date;    // 2023-03-31

    // 最小 取前4位字符 年 = 2022
    $min_updatetime_year = substr($min_updatetime, 0, 4);
    // 最小 取前5位和6位字符 月 = 05
    $min_updatetime_month = substr($min_updatetime, 5, 2);
    // 最大 取前4位字符 2024
    $max_updatetime_year = substr($max_updatetime, 0, 4);
    // 最大 取前5位和6位字符 月 = 12
    $max_updatetime_month = substr($max_updatetime, 5, 2);

    $quarterArr = Utils::generateQuarterDates($min_updatetime_year, $min_updatetime_month, $max_updatetime_year, $max_updatetime_month);

    $dateTimeArr = Utils::convertQuarterDates($quarterArr);

    $dateStampsArr = Utils::dateTimeArrToTimestamps($dateTimeArr);

    // 查询数据 - 聘任职称
    $jobTitleModel = new \app\admin\model\dicts\Jobtitle;
    $jobTitle = $jobTitleModel->field("jobtitle")->select();
    $jobTitleArr = json_decode(json_encode($jobTitle), true);

    // 查询数据 - 学历
    $educationBakModel = new \app\admin\model\dicts\Educationbak;
    $educationBak = $educationBakModel->field("educationbak")->select();
    $educationBakArr = json_decode(json_encode($educationBak), true);

    // 查询数据 - 年金
    $yearPayModel = new \app\admin\model\dicts\Yearpay;
    $yearPay = $yearPayModel->field("yearpay")->select();
    $yearPaykArr = json_decode(json_encode($yearPay), true);

    $jobTitleQuarterArr = [];
    $educationBakQuarterArr = [];
    $yearPayQuarterArr = [];

    // 遍历 $dateStampsArr，进行批量查询
    foreach ($dateStampsArr as $index => $item) {
      $nurseinfoModel = new \app\admin\model\fssy\Nurseinfo;

      $jobTitleCounts = Utils::arrSetZero($jobTitleArr, "jobtitle");
      $educationBakCounts = Utils::arrSetZero($educationBakArr, "educationbak");
      $yearPayCounts = Utils::arrSetZero($yearPaykArr, "yearpay");

      $data = $nurseinfoModel
        ->with(["dictsusejobtitle", "dictseducationbak"])
        ->whereTime('fa_fssy_nurseinfo.updatetime', '>=', $item["start"])
        ->whereTime('fa_fssy_nurseinfo.updatetime', '<=', $item["end"]);
      if ($departmentID !== "all") {
        $data = $data->where("department_id", '=', $departmentID);
      }
      $data = $data->select();

      foreach ($data as $nurse) {
        $jobTitle = $nurse->dictsusejobtitle->jobtitle;
        $educationBak = $nurse->dictseducationbak->educationbak;
        $yearPay = Utils::calcYearsStep($nurse->work_years);

        if (array_key_exists($jobTitle, $jobTitleCounts)) {
          $jobTitleCounts[$jobTitle]++;
        }
        if (array_key_exists($educationBak, $educationBakCounts)) {
          $educationBakCounts[$educationBak]++;
        }
        if (array_key_exists($yearPay, $yearPayCounts)) {
          $yearPayCounts[$yearPay]++;
        }
      }

      $jobTitleItemArr = json_decode(json_encode($jobTitleCounts), true);
      $jobTitleItemArr['range_title'] = $quarterArr[$index];
      $jobTitleItemArr['department'] = $department;
      array_push($jobTitleQuarterArr, $jobTitleItemArr);

      $educationBakItemArr = json_decode(json_encode($educationBakCounts), true);
      $educationBakItemArr['range_title'] = $quarterArr[$index];
      $educationBakItemArr['department'] = $department;
      array_push($educationBakQuarterArr, $educationBakItemArr);

      $yearPayItemArr = json_decode(json_encode($yearPayCounts), true);
      $yearPayItemArr['range_title'] = $quarterArr[$index];
      $yearPayItemArr['department'] = $department;
      array_push($yearPayQuarterArr, $yearPayItemArr);
    }

    $data = [
      'jobTitleQuarterArr' => $jobTitleQuarterArr,
      'educationBakQuarterArr' => $educationBakQuarterArr,
      'yearPayQuarterArr' => $yearPayQuarterArr,
    ];
    return $data;
  }

  /***
   * 获取最小最大值
   * @param $a
   * @param $b
   * @param $c
   * @return array ['min' => $min, 'max' => $max]
   */
  public static function findMinAndMax($a, $b, $c)
  {
    $min = min($a, $b, $c);
    $max = max($a, $b, $c);
    return ['min' => $min, 'max' => $max];
  }


  /**
   * 根据季度字符串返回季度的 开始 和 结束 日期的 时间戳格式
   *
   * @param [strgin] $start = "2023-04-01"
   * @param [string] $end = "2023-06-30"
   * @return array ['start_timestamp' => 1680278400, 'end_timestamp' => 1688140799]
   */
  public static function signalQuarterStartEndTimestamp($start, $end)
  {
    date_default_timezone_set("PRC"); // 设置时区为东八区
    $startDate = $start . " 00:00:00";
    $endDate = $end . " 23:59:59";
    $startDate = strtotime($startDate);
    $endDate = strtotime($endDate);
    return array('start_timestamp' => $startDate, 'end_timestamp' => $endDate);
  }


  public static function getLonginInfo($info, $group)
  {
    $id = $info['id'];
    $departmentId = $info['department_id'];
    $userName = $info['username'];
    $nickname = $info['nickname'];

    // 通过部门id获取部门名称
    if ($departmentId != null) {
      $departmentModel = new \app\admin\model\dicts\Department;
      $departmentInfo = $departmentModel->where('id', $departmentId)->find();
      $departmentName = $departmentInfo['department'];
    } else {
      $departmentName = null;
    }



    $groupName = $group[0]['name'];
    $groupPId = $group[0]['pid'];

    return [
      'id' => $id,
      'departmentId' => $departmentId,
      'departmentName' => $departmentName,
      'userName' => $userName,
      'nickName' => $nickname,
      'groupName' => $groupName,
      'groupPId' => $groupPId
    ];
  }
}
